package c.e.b.g;

import c.e.b.j.c;
import c.e.b.j.d;
import c.e.b.l.a;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Objects;
import java.util.Set;
import java.util.concurrent.Executor;

/* compiled from: com.google.firebase:firebase-components@@16.0.0 */
public class k extends a {
    public static final /* synthetic */ int e = 0;
    public final Map<d<?>, t<?>> a = new HashMap();
    public final Map<Class<?>, t<?>> b = new HashMap();
    public final Map<Class<?>, t<Set<?>>> c = new HashMap();
    public final s d;

    public k(Executor executor, Iterable<g> iterable, d<?>... dVarArr) {
        Iterator it;
        d dVar;
        m mVar;
        m mVar2;
        s sVar = new s(executor);
        this.d = sVar;
        ArrayList arrayList = new ArrayList();
        arrayList.add(d.c(sVar, s.class, d.class, c.class));
        for (g components : iterable) {
            arrayList.addAll(components.getComponents());
        }
        for (Object obj : dVarArr) {
            if (obj != null) {
                arrayList.add(obj);
            }
        }
        HashMap hashMap = new HashMap(arrayList.size());
        Iterator it2 = arrayList.iterator();
        while (it2.hasNext()) {
            dVar = (d) it2.next();
            mVar = new m(dVar);
            for (Class nVar : dVar.a) {
                n nVar2 = new n(nVar, dVar.b() ^ 1, null);
                if (!hashMap.containsKey(nVar2)) {
                    hashMap.put(nVar2, new HashSet());
                }
                Set set = (Set) hashMap.get(nVar2);
                if (set.isEmpty() || nVar2.b) {
                    set.add(mVar);
                } else {
                    throw new IllegalArgumentException(String.format("Multiple components provide %s.", new Object[]{nVar}));
                }
            }
        }
        for (Set<m> it3 : hashMap.values()) {
            for (m mVar3 : it3) {
                for (o oVar : mVar3.a.b) {
                    if ((oVar.c == 0 ? 1 : null) != null) {
                        Set<m> set2 = (Set) hashMap.get(new n(oVar.a, oVar.a(), null));
                        if (set2 != null) {
                            for (m mVar4 : set2) {
                                mVar3.b.add(mVar4);
                                mVar4.c.add(mVar3);
                            }
                        }
                    }
                }
            }
        }
        HashSet hashSet = new HashSet();
        for (Set addAll : hashMap.values()) {
            hashSet.addAll(addAll);
        }
        HashSet hashSet2 = new HashSet();
        Iterator it4 = hashSet.iterator();
        while (it4.hasNext()) {
            mVar2 = (m) it4.next();
            if (mVar2.a()) {
                hashSet2.add(mVar2);
            }
        }
        int i = 0;
        while (!hashSet2.isEmpty()) {
            mVar2 = (m) hashSet2.iterator().next();
            hashSet2.remove(mVar2);
            i++;
            for (m mVar5 : mVar2.b) {
                mVar5.c.remove(mVar2);
                if (mVar5.a()) {
                    hashSet2.add(mVar5);
                }
            }
        }
        if (i == arrayList.size()) {
            d dVar2;
            Iterator it5 = arrayList.iterator();
            while (it5.hasNext()) {
                dVar2 = (d) it5.next();
                this.a.put(dVar2, new t(new h(this, dVar2)));
            }
            for (Entry entry : this.a.entrySet()) {
                d dVar3 = (d) entry.getKey();
                if (dVar3.b()) {
                    t tVar = (t) entry.getValue();
                    for (Class put : dVar3.a) {
                        this.b.put(put, tVar);
                    }
                }
            }
            for (d dVar22 : this.a.keySet()) {
                for (o oVar2 : dVar22.b) {
                    if ((oVar2.b == 1 ? 1 : null) != null) {
                        if (!this.b.containsKey(oVar2.a)) {
                            throw new u(String.format("Unsatisfied dependency for component %s: %s", new Object[]{dVar22, oVar2.a}));
                        }
                    }
                }
            }
            HashMap hashMap2 = new HashMap();
            for (Entry entry2 : this.a.entrySet()) {
                dVar = (d) entry2.getKey();
                if (!dVar.b()) {
                    t tVar2 = (t) entry2.getValue();
                    for (Class cls : dVar.a) {
                        if (!hashMap2.containsKey(cls)) {
                            hashMap2.put(cls, new HashSet());
                        }
                        ((Set) hashMap2.get(cls)).add(tVar2);
                    }
                }
            }
            for (Entry entry3 : hashMap2.entrySet()) {
                this.c.put((Class) entry3.getKey(), new t(new i((Set) entry3.getValue())));
            }
            return;
        }
        arrayList = new ArrayList();
        it = hashSet.iterator();
        while (it.hasNext()) {
            m mVar6 = (m) it.next();
            if (!(mVar6.a() || mVar6.b.isEmpty())) {
                arrayList.add(mVar6.a);
            }
        }
        throw new p(arrayList);
    }

    public <T> a<T> c(Class<T> cls) {
        Objects.requireNonNull(cls, "Null interface requested.");
        return (a) this.b.get(cls);
    }

    public <T> a<Set<T>> d(Class<T> cls) {
        t tVar = (t) this.c.get(cls);
        if (tVar != null) {
            return tVar;
        }
        return j.a;
    }
}
